<template>
	<view>
		<view class="search">
			<u-icon name="search" size="28"></u-icon>
			<text>女靴</text>
		</view>
		<view class="main">
			<scroll-view scroll-y="true" class="left">
				<view>
					<view class="tap" :class="activeIndex === index ? 'active' : ''" v-for="(item,index) in firstCate" :key="item.id" @click="onchange(index)">{{item.name}}</view>
				</view>
			</scroll-view>
			<scroll-view scroll-y="true" class="right">
				<view v-if="flag">
					<AdsSwiper :dataList="bannerList" class="banner"></AdsSwiper>
						<view class="list-item" v-for="item in firstCate[activeIndex].children" :key="item.id">
							<view class="list-item-title">
								<text class="title">{{item.name}}</text>
								<navigator url=""><text class="all">全部 ></text></navigator>
							</view>
							<view class="goods-list">
								<view class="goods-item" v-for="item in item.goods">
									<navigator :url="`/pages/detail/detail?id=${item.id}`"><image :src="item.picture" mode=""></image></navigator>
									<text class="name">{{item.name}}</text>
									<text class="price">￥{{item.price}}</text>
								</view>
							</view>
						</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import AdsSwiper from '@/pages/index/components/AdsSwiper.vue'
	export default {
		data() {
			return {
				bannerList: [],
				firstCate: [],
				activeIndex: 0,
				flag: false
			};
		},
		onLoad() {
			this.getData1()
			this.getData2()
		},
		methods:{
			async getData1(){
				const res1 = await this.$http({
					url: '/home/banner',
					data: {
						distributionSite: 2
					}
				})
				this.bannerList = res1.data.result
			},
			async getData2(){
				const res2 = await this.$http({
					url: '/category/top'
				})
				this.firstCate = res2.data.result
				this.flag = true
			},
			onchange(index){
				this.activeIndex = index
			}
		},
		components:{
			AdsSwiper
		}
	}
</script>

<style lang="scss">
page{
	background-color: white;
	height: 100%;
	view{
		height: 100%;
		display: flex;
		flex-direction: column;
		.search{
			width: 90%;
			height: 64rpx;
			display: flex;
			flex-direction: row;
			justify-content: start;
			align-items: center;
			background-color: #f2f2f2;
			color: #909399;
			margin: 0 auto;
			border-radius: 30rpx;
			padding: 30rpx 30rpx;
			text{
				margin-left: 10rpx;
			}
		}
		.main{
			flex: 1;
			padding-top: 20rpx;
			display: flex;
			flex-direction: row;
			.left{
				height: 100%;
				flex-shrink: 0;
				width: 180rpx;
				background-color: #f6f6f6;
				view{
					display: flex;
					flex-direction: column;
					justify-content: start;
					.tap{
						display: flex;
						height: 96rpx;
						font-size: 26rpx;
						color: #595c63;
						justify-content: center;
						justify-items: center;
						text-align: center;
						position: relative;
						&::before{
							position: absolute;
							content: '';
							width: 50%;
							left: 25%;
							bottom: 0;
							border-top: 1rpx solid #e3e4e7;
						}
						&:last-child::before{
							display: none;
						}
					}
					.active{
						background-color: #fff;
						&::after{
							content: '';
							background-color: #27ba9b;
							width: 8rpx;
							height: 100%;
							position: absolute;
							left: 0;
							top: 0;
						}
						&::before{
							display: none;
						}
					}
				}
			}
			.right{
				height: 100%;
				width: 570rpx;
				display: flex;
				flex-direction: column;
				view{
					padding: 0 10rpx;
					.banner{
						height: 200rpx;
					}
					.list-item{
						margin-top: 10rpx;
						height: fit-content;
						.list-item-title{
							display: flex;
							flex-direction: row;
							justify-content: space-between;
							padding: 20rpx 0;
							.all{
								font-size: 24rpx;
								color: #999;
							}
						}
						.goods-list{
							display: flex;
							flex-direction: row;
							flex-wrap: wrap;
							justify-content: start;
							.goods-item{
								display: flex;
								flex-direction: column;
								width: 150rpx;
								margin-right: 20rpx;
								height: fit-content;
								margin-bottom: 20rpx;
								image{
									 width: 150rpx;
									 height: 150rpx;
								}
								.name{
									display: -webkit-box;
									-webkit-box-orient: vertical;
									-webkit-line-clamp: 2;
									font-size: 22rpx;
									color: #333;
									overflow: hidden;
								}
								.price{
									font-size: 18rpx;
									color: #cf4444;
								}
							}
						}
					}
				}
			}
		}
	}
}
</style>
